package physics.globalforce;

import physics.Assembly;
import physics.EnvironmentSingleton.EnvironmentalForce;
import physics.Force;
import physics.component.Mass;


/**
 * Global viscosity of environment.
 *
 * @author Kevin Gao, Connor Gordon
 *
 */
public class Viscosity extends GlobalForce {

    private double myViscosityMagnitude = 0;

    /**
     * Default constructor for viscosity force using default values.
     */
    public Viscosity () {
        super(EnvironmentalForce.VISCOSITY);
    }

    /**
     * Constructs a new gravity force with given direction and magnitude.
     *
     * @param scale Scalar for environment viscosity effects
     */
    public Viscosity (final double scale) {
        super(EnvironmentalForce.VISCOSITY);
        myViscosityMagnitude = scale;
    }

    @Override
    protected final Force getCalculatedForce (final Mass target,
            final Assembly asm) {
        Force viscosity = new Force(-target.getVelocity().getDirection(),
                myViscosityMagnitude * target.getVelocity().getMagnitude());
        viscosity.scale(1 / target.getMass());
        return viscosity;
    }

    /**
     * Sets Global Gravity parameters.
     *
     * @param scale Scalar that controls magnitude of viscosity force
     */
    public final void setViscosityMagnitude (final double scale) {
        myViscosityMagnitude = scale;
    }

}
